package com.five.admin.controller;

import com.five.controller.BaseController;
import com.five.admin.service.CourseService;
import com.five.entity.Course;
import com.five.entity.qo.CourseQo;
import com.five.entity.qo.InsertCourseQo;
import com.five.vo.BaseResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author: star
 * @Date: 2021-05-21 13:58
 */
@Controller
@RequestMapping("course")
@Api(tags = "课程业务接口")
@CrossOrigin
public class CourseController extends BaseController {
    @Autowired
    private CourseService courseService;

    /**
     * @return 课程列表
     */
    @ResponseBody
    @RequestMapping(value = "courseList",method = RequestMethod.GET)
    @ApiOperation("获取课程列表接口")
    public BaseResultVO courseList(){
        List<CourseQo> courseList = courseService.getCourseList();
        return  successResp(courseList);
    }

    /**
     * 添加课程
     * @param insertCourseQo
     * @return 提示信息
     */
    @ResponseBody
    @RequestMapping(value = "addCourse",method = RequestMethod.POST)
    @ApiOperation("添加课程信息接口")
    public BaseResultVO addCourse(InsertCourseQo insertCourseQo){
        courseService.insertCourse(insertCourseQo);
        return successRespWithMessage("添加成功");
    }

    @ResponseBody
    @RequestMapping(value = "deleteCourse",method = RequestMethod.GET)
    @ApiOperation("删除课程信息接口")
    public BaseResultVO deleteCourse(Course course){
        courseService.deleteCourse(course);
        return successRespWithMessage("删除成功");
    }

    @ResponseBody
    @RequestMapping(value = "fuzzyQueryCourse",method = RequestMethod.GET)
    @ApiOperation("模糊查询课程列表接口")
    public BaseResultVO fuzzyQueryCourse(CourseQo courseQo){
        List<CourseQo> courseQoList = courseService.fuzzyQueryByTitle(courseQo);
        return  successResp(courseQoList);
    }

    @ResponseBody
    @RequestMapping(value = "selectById",method = RequestMethod.GET)
    @ApiOperation("通过id获取课程信息接口")
    public BaseResultVO selectById(CourseQo courseQo){
        CourseQo resultCourseQo = courseService.selectById(courseQo);
        return  successResp(resultCourseQo);
    }

    @ResponseBody
    @RequestMapping(value = "updateCourse",method = RequestMethod.POST)
    @ApiOperation("修改课程信息接口")
    public BaseResultVO updateCourse(InsertCourseQo insertCourseQo){
        courseService.updateCourse(insertCourseQo);
        return successRespWithMessage("修改成功");
    }
}
